<!--
 * @Author: your name
 * @Date: 2020-02-25 13:32:39
 * @LastEditTime: 2020-03-19 13:47:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \福路德扫码系统\html\cksm.html
 -->
<!doctype html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>Hello APP</title>
	<link rel="stylesheet" type="text/css" href="../css/vant.css">
	<link rel="stylesheet" type="text/css" href="../css/base.css" />
	<link rel="stylesheet" type="text/css" href="../css/local.css" />
	<script type="text/javascript" src="../script/jquery.js"></script>
	<script type="text/javascript" src="../script/vue.min.js"></script>
	<script type="text/javascript" src="../script/vant.min.js"></script>
	<script type="text/javascript" src="../script/fastclick.js"></script>
	<script type="text/javascript" src="../script/base.js"></script>
	<script type="text/javascript" src="../script/app-tree.js"></script>
	<style type="text/css">
		.van-nav-bar__left {
			white-space: pre;
			width: auto;
			/* color: #1989fa; */
			font-weight: 700;
			font-size: 15px;
		}

		.moudle {
			padding: 15px 15px 0 15px;
			text-align: center;
		}

		.m-r {
			height: 70px;
			line-height: 70px;
			border-radius: 6px;
			color: #fff;
			letter-spacing: 2px;
			font-size: 15px;
		}

		.mr-c1 {
			background-image: linear-gradient(to bottom right, #ea402f, #ff7462);
		}

		.mr-c2 {
			background-image: linear-gradient(to bottom right, #f4700f, #ffa65e);
		}

		.mr-c3 {
			background-image: linear-gradient(to bottom right, #3271ea, #6797fd);
		}

		.mr-c4 {
			background-image: linear-gradient(to bottom right, #32bbfb, #24e3ff);
		}

		.part {
			padding: 15px;
		}

		.part>div {
			border-radius: 6px;
			box-shadow: 0px 1px 5px rgb(200, 198, 198);
			padding-top: 15px;
			background-color: #fff;
		}

		.label {
			/* margin-left: -10px;
			margin-right: -10px; */
			padding-bottom: 10px;
		}

		.label span {
			padding: 6px 10px;
			background: #1989fa;
			color: #fff;
			font-size: 13px;
			display: inline-block;
		}

		.per {
			padding: 15px 0;
		}

		.date {
			text-align: right;
			font-size: 12px;
			color: #9e9e9e;
			padding: 4px 0;
		}

		.more {
			text-align: center;
			color: #9e9e9e;
			line-height: 40px;
		}

		.title {
			position: relative;
		}

		.title img {
			vertical-align: middle;
			width: 22px;
			margin-right: 5px;
		}

		.title span {
			vertical-align: middle;
		}

		.sub-title {
			font-size: 13px;
			color: #9e9e9e;
		}

		.d {
			background-color: #eaeaea;
			padding: 13px 20px;
			border-radius: 6px;
			color: #949595;
			font-size: 14px;
		}

		.dt {
			display: inline-block;
			width: 60px;
			vertical-align: middle;
		}

		.dn {
			color: #deab63;
			font-size: 16px;
			vertical-align: middle;
		}

		.gr {
			text-align: center;
			font-size: 13px;
			padding-bottom: 10px;
			position: relative;
		}



		.gr img {
			height: 30px;
			position: relative;
		}

		.gr .img {
			width: 40px;
			height: 40px;
			text-align: center;
			border-radius: 20px;
			padding: 7px;
			display: inline-block;
		}

		.gr .img>img {
			height: 100%;
		}


		.gr .mn {
			line-height: 22px;
			padding: 4px 8px;
			overflow: hidden;
			text-overflow: ellipsis;
			height: 50px;
			/*white-space: nowrap;*/
		}

		.banner {
			border-radius: 10px;
			overflow: hidden;
		}

		.banner img {
			width: 100%;
		}

		.label-2 {
			/* padding-bottom: 10px; */
			padding: 10px 10px 18px 10px;
			color: #455a64;
			font-size: 15px;
		}

		.bb {
			border-bottom: 1px solid #f6f7f7;
		}

		.tag-num {
			position: absolute;
			right: 20px;
			top: -8px;
			min-width: 16px;
			height: 16px;
			border-radius: 8px;
			text-align: center;
			line-height: 16px;
			font-size: 12px;
			color: #fff;
			background: #ea402f;
		}

		.tag-num1 {
			position: absolute;
			right: 32px;
			top: -6px;
			min-width: 16px;
			height: 16px;
			border-radius: 8px;
			text-align: center;
			line-height: 16px;
			font-size: 12px;
			color: #fff;
			background: #ea402f;

		}

		.van-col--6 {
			padding-left: 0 !important;
			padding-right: 0 !important;
		}
	</style>
</head>

<body>
	<div id="app" v-cloak>
		<div class="box">
			<van-nav-bar-main>
				<div slot="left">欢迎您,{{userData.ClassName}}-{{userData.UserName}}</div>
			</van-nav-bar-main>
			<div class="content">
				<van-pull-refresh :disabled="loadingDisabled" v-model="refreshLoading" @refresh="onRefresh">
					<div class="content-refresh">
						<div class="moudle">
							<div class="banner"><img src="../image/banner.png" /></div>
						</div>
						<div class="part">
							<div>
								<div v-for="row in roleList" v-if="row.Node.length && row.TreeName == '零件质量模块'">
									<div class="label-2"><span>{{row.TreeName}}</span></div>
									<div class="bb">
										<van-row gutter="10">

											<van-col span="8" v-for="item in row.Node">
												<div class="gr" @click="openWin(item)">
													<div class="img" :style="{'background': item.AP_Colour}">
														<img :src="serverIP + item.PIC_PH" />
													</div>

													<div class="mn">{{item.APFunName}} </div>
													<span class="tag-num"
														v-if="item.APFunName=='零件质量问题实时提醒' && ljzlNum ">{{ljzlNum}}</span>
												</div>
											</van-col>
										</van-row>
									</div>
								</div>
								<div>
									<div class="label-2"><span>审批事项</span></div>
									<div class="bb">
										<van-row gutter="10">
											<van-col span="6">
												<div class="gr" @click="openApprovalList('可评审',3)">
													<img src="../image/d-1.png" />

													<div class="mn">可评审</div>

													<span class="tag-num"
														v-if="approvalNumData1">{{approvalNumData1}}</span>
												</div>
											</van-col>
											<van-col span="6">
												<div class="gr" @click="openApprovalList('已处理',4)">
													<img src="../image/d-2.png" />

													<div class="mn">已处理</div>
												</div>
											</van-col>
											<van-col span="6">
												<div class="gr" @click="openApprovalList('已发起',2)">
													<img src="../image/d-3.png" />

													<div class="mn">已发起</div>
												</div>
											</van-col>
											<van-col span="6">
												<div class="gr" @click="openApprovalList('待评审',6)">
													<img src="../image/d-4.png" />

													<div class="mn">待评审</div>
													<span class="tag-num"
														v-if="approvalNumData7">{{approvalNumData7}}</span>
												</div>
											</van-col>
										</van-row>
										<van-row gutter="10">
											<van-col span="6">
												<div class="gr" @click="openMsgList">
													<img src="../image/msg.png" />

													<div class="mn">消息列</div>
													<span class="tag-num" v-if="MsgNum">{{MsgNum}}</span>
												</div>
											</van-col>
											<van-col span="6">
												<div class="gr" @click="openApprovalList('我的审批',99)">
													<img src="../image/msg.png" />

													<div class="mn">我的审批</div>
													<span class="tag-num" v-if="MsgNum">{{MyCkCount}}</span>
												</div>
											</van-col>
										</van-row>
									</div>
								</div>

								<div v-for="row in roleList" v-if="row.Node.length && row.TreeName != '零件质量模块'">
									<div class="label-2"><span>{{row.TreeName}}</span></div>
									<div class="bb">
										<van-row gutter="10">

											<van-col span="8" v-for="item in row.Node">
												<div class="gr" @click="openWin(item)">
													<div class="img" :style="{'background': item.AP_Colour}">
														<img :src="serverIP + item.PIC_PH" />
														<span class="tag-num1"
															v-if="approvalNumData5 && item.APFunName == '单据确认'">{{approvalNumData5}}</span>
														<span class="tag-num1"
															v-if="approvalNumData6 && item.APFunName == '单据复核'">{{approvalNumData6}}</span>
													</div>

													<div class="mn">{{item.APFunName}}</div>
													<span class="tag-num"
														v-if="item.APFunName=='采购请购月度汇总' && approvalNumVouchM  ">{{approvalNumVouchM}}</span>
													<span class="tag-num"
														v-if="item.APFunName=='采购订单审批' && approvalOrder  ">{{approvalOrder}}</span>
													<span class="tag-num"
														v-if="item.APFunName=='采购订单批量审批' && approvalNumBatch  ">{{approvalNumBatch}}</span>
													<span class="tag-num"
														v-if="item.APFunName=='实验评审单' && SYPSDNum  ">{{SYPSDNum}}</span>
												</div>
											</van-col>
										</van-row>
									</div>
								</div>

							</div>
						</div>
						<div class="part" v-if="getMyApprovalList.length">
							<div>
								<div class="label"><span>审批进度</span></div>
								<div>
									<van-cell-group>
										<van-cell v-for="(row,index) in getMyApprovalList" v-if="index < 3"
											@click="intoApproval(row)">
											<div class="title"><img src="../image/sp.png" /><span>{{row.Title}}</span>
											</div>
											<div>
												<div class="sub-title" v-for="item in row.FRemarks.split('|')">{{item}}
												</div>
											</div>
											<div class="per">
												<van-progress :percentage="100*row.ApprovalSortCZ/row.SortCount"
													:pivot-text="getApprovalText(row)"></van-progress>
											</div>
											<div class="date">
												<span>发起时间：{{row.CreateTime.split('.')[0].replace(/T/g,' ')}}</span>
											</div>

										</van-cell>

									</van-cell-group>
									<div class="more" v-if="getMyApprovalList.length > 3"
										@click="openApprovalList('已发起',2)">查看更多</div>
								</div>
							</div>
						</div>
					</div>
				</van-pull-refresh>


			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	var vm;
	apiready = function () {

		APP.exitApp();


		function ping(ip) {

			api.ajax({
				url: 'http://' + ip + '/Frame/SqlData?cmdname=ConnectionTest',
				data: {
					values: {}
				},
				timeout: 20,
				method: 'post',
				dataType: 'json'
			}, function (ret, err) {
				if (ret) {
					window.localStorage.setItem('serverIP', ip);
				} else {

				}
			});
		}


		vm = new Vue({
			el: '#app',
			data: {
				showLoading: false,
				loadingDisabled: false,
				serverIP: 'http://' + APP.serverIP(),
				refreshLoading: false,
				roleList: [],
				userData: APP.getUserInfo(),
				getMyApprovalList: [],
				personList: [],
				approvalNumData1: 0,
				approvalNumData2: 0,
				approvalNumData3: 0,
				approvalNumData4: 0,
				approvalNumData5: 0,
				approvalNumData6: 0,
				approvalNumData7: 0,
				ljzlNum: 0,//零件质量问题
				//采购部分
				approvalNumVouchM: 0,
				approvalOrder: 0,
				approvalNumBatch: 0,
				MsgNum: 0,
				SYPSDNum: 0,
				MyCkCount:0
			},
			created: function () {
				var that = this;
				APP.ajax('getCkUserList', {}, function (res) {

					that.personList = res.ds;

					setInterval(function () {
						that.getMyApproval();
						that.getApprovalNum();



					}, 5000)
					that.getMyApproval();
					that.getApprovalNum();
				})
				that.getUserRole();
				// alert(JSON.stringify(APP.getUserInfo()))
			},
			methods: {
				getUserRole: function () {
					var that = this;
					that.showLoading = true;
					APP.ajax('getAppModuleByRoleId', { RoleId: APP.getUserInfo().RoleId, APPType: 2 }, function (res) {
						that.showLoading = false;
						// that.roleList = res.ds;

						var roleList = [];
						for (var i in res.ds) {
							var x = 0;
							for (var j in roleList) {
								if (res.ds[i].FunType == roleList[j].TreeName) {
									x = 1;
									roleList[j].Node.push(res.ds[i]);
								}
							}
							if (x == 0) {
								roleList.push({
									TreeName: res.ds[i].FunType,
									Node: [res.ds[i]]
								})
							}
						}
						that.roleList = roleList;
						// console.log('roleList', JSON.stringify(that.roleList))
					})
				},
				getApprovalText: function (row) {
					var that = this;
					var str = '';
					if (row.CurrentApprovalIDs.length > 1) {
						str = '多人';
						if (row.SignedWay == 0) {
							str += '或签';
						} else {
							str += '会签';
						}

					} else {
						for (var i in that.personList) {
							if (row.CurrentApprovalIDs[0] == that.personList[i].UserID) {
								str = that.personList[i].UserName + '待审批'
								break;
							}
						}
					}
					return str;
				},
				getMyApproval: function () {
					var that = this;
					var obj = {
						size: 1,
						page: 999
					}
					APP.ajax('IStartedFlow', obj, function (res) {
						that.refreshLoading = false;
						for (var i in res.ds) {
							res.ds[i].CurrentApprovalIDs = res.ds[i].CurrentApprovalIDs.replace(/^,+/, "").replace(/,+$/, "").split(',');
						}
						that.getMyApprovalList = res.ds;
					}, function (err) {
						vm.showLoading = false;
						vm.refreshLoading = false;
						pingIP(APP.serverIP1);
						pingIP(APP.serverIP2);
					})
				},
				getApprovalNum: function () {
					var that = this;
					APP.ajax('GetFlowLogCount1', {}, function (res) {
						that.approvalNumData1 = res.ds1[0].DSPNum;
						that.approvalNumData2 = res.ds2[0].YSPNum;
						that.approvalNumData3 = res.ds[0].FQNum;
						that.approvalNumData4 = res.ds3[0].CSNum;
						that.approvalNumData5 = res.ds4[0].QRNum;
						that.approvalNumData6 = res.ds5[0].FHNum;

						that.approvalNumData7 = res.ds6[0].FDPNum;
						that.approvalNumVouchM = res.ds7[0].FDPNum;
						that.approvalOrder = res.ds8[0].FDPNum;
						that.approvalNumBatch = res.ds9[0].FDPNum;
						that.ljzlNum = res.ds10[0].ZlhzNum;
						that.MsgNum = res.ds11[0].MsgNum;
						that.SYPSDNum = res.ds12[0].SYPSDNum;
						that.MyCkCount = res.ds13[0].MyCkCount;
						api.setAppIconBadge({
							badge: that.approvalNumData1
						});


					}, function (err) {
						vm.showLoading = false;
						vm.refreshLoading = false;
						pingIP(APP.serverIP1);
						pingIP(APP.serverIP2);
					})
				},
				onRefresh: function () {
					var that = this;
					setTimeout(function () {
						that.refreshLoading = true;
						that.getMyApproval();
						that.getUserRole();
					}, 500)

				},
				openApprovalList: function (title, type) {
					var that = this;
					api.openWin({
						name: 'approvalList',
						url: 'approvalList.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: true,
						pageParam: {
							titleName: title,
							type: type
						}
					})
				},
				intoApproval: function (row) {
					var that = this;
					var page = '';
					if (row.TableName == 'Ck_Review') {
						page = 'approvalPage1';
					} else if (row.TableName == 'EC_ProjectChgRevRec') {
						page = 'approvalPage2';
					} else if (row.TableName == 'EC_ProjectChgPrcCfm') {
						page = 'approvalPage3';
					}
					api.openWin({
						name: page,
						url: page + '.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: true,
						pageParam: {
							id: row.PKValue
						}
					})
				},
				openReport: function (row) {
					var that = this;
					var pageParam = {}
					if (row.Para) {
						var paraArray = row.Para.split(';');
						for (var i in paraArray) {
							var paraRowArray = paraArray[i].split('=');
							if (paraRowArray[1] == 'true') {
								paraRowArray[1] = true;
							}
							if (paraRowArray[1] == 'false') {
								paraRowArray[1] = false;
							}
							pageParam[paraRowArray[0]] = paraRowArray[1];
						}
					}
					pageParam.titleName = row.APFunName;
					api.openWin({
						name: row.AP_Link,
						url: row.AP_Link,
						reload: true,
						slidBackEnabled: false,
						scaleEnabled: row.FunType == '报表展示' ? true : false,
						allowEdit: true,
						pageParam: pageParam
					})
				},
				openWin: function (row) {
					var that = this;
					// console.log('row', JSON.stringify(row))
					var pageParam = {}
					if (row.Para) {
						var paraArray = row.Para.split(';');
						for (var i in paraArray) {
							var paraRowArray = paraArray[i].split('=');
							if (paraRowArray[1] == 'true') {
								paraRowArray[1] = true;
							}
							if (paraRowArray[1] == 'false') {
								paraRowArray[1] = false;
							}
							pageParam[paraRowArray[0]] = paraRowArray[1];
						}
					}
					pageParam.titleName = row.APFunName;
					if (row.AP_Link == 'Web/Index') {
						api.openWin({
							name: row.AP_Link,
							url: 'Web/Index.html',
							reload: true,
							slidBackEnabled: false,
							scaleEnabled: false,
							allowEdit: true,
							pageParam: {
								url: row.Para,
								title: row.APFunName
							}
						})
					} else {
						api.openWin({
							name: row.AP_Link,
							url: row.AP_Link + '.html',
							reload: true,
							slidBackEnabled: false,
							scaleEnabled: row.FunType == '报表展示' ? true : false,
							allowEdit: true,
							pageParam: pageParam
						})
					}
				},
				openLJWin: function (index) {
					var that = this;
					if (index == 1) {
						api.openWin({
							name: 'config/report',
							url: 'config/report.html',
							reload: true,
							slidBackEnabled: false,
							scaleEnabled: true,
							allowEdit: true,
							pageParam: {
								titleName: '国内外问题展示',
								objName: '质量问题清单报表'
							}
						})
					} else if (index == 2) {
						api.openWin({
							name: 'config/report',
							url: 'config/report.html',
							reload: true,
							slidBackEnabled: false,
							scaleEnabled: true,
							allowEdit: true,
							pageParam: {
								titleName: '零件质量问题清单',
								objName: '所有问题清单报表'
							}
						})
					} else if (index == 3) {
						api.openWin({
							name: 'partProblem',
							url: 'partProblem.html',
							reload: true,
							slidBackEnabled: false,
							scaleEnabled: false,
							allowEdit: true,
							pageParam: {

							}
						})
					}
				},
				//品质消息提醒列表
				openMsgList() {
					api.openWin({
						name: 'pzMsgList',
						url: 'pzMsgList.html',
						reload: true,
						slidBackEnabled: false,
						allowEdit: true,
						pageParam: {
							titleName: '品质消息提醒列表'
							// type: type
						}
					})
				},
				loginOut: function () {
					var that = this;
					that.$dialog.confirm({
						title: '提示',
						message: '是否退出当前账号?'
					}).then(function () {

						window.localStorage.removeItem('userInfo');
						api.sendEvent({
							name: 'clearLoginInfo'
						});
						api.closeToWin({
							name: 'root'
						});
					}).catch(function () {

					});
				},
			}
		})
	};
</script>

</html>